// 从后端 API 获取科室数据
let departments = {};

fetch('/webapi/patient/introduction')
    .then(response => response.json())
    .then(data => {
        const select = document.getElementById('departmentSelect');
        data.forEach(department => {
            // 将科室数据保存到全局对象
            departments[department.name] = {
                description: department.description,
                image: department.imageUrl // 仍然保存图片地址，以便可能的后续使用
            };

            // 将科室名称添加到下拉选项
            const option = document.createElement('option');
            option.value = department.name;
            option.textContent = department.name;
            select.appendChild(option);
        });
    })
    .catch(error => console.error('获取科室数据失败:', error));

// 显示对应科室信息
function showDepartmentInfo() {
    const selectedDepartment = document.getElementById("departmentSelect").value;
    const content = document.getElementById("departmentContent");
    const description = document.getElementById("departmentDescription");
    const departmentName = document.getElementById("departmentName"); // 新增元素用于显示科室名称

    if (selectedDepartment && departments[selectedDepartment]) {
        departmentName.textContent = selectedDepartment; // 显示科室名称
        description.textContent = departments[selectedDepartment].description;
        content.style.display = "flex"; // 显示内容
    } else {
        content.style.display = "none"; // 隐藏内容
    }
}
